<template>
	<section class="content-box">
		<div>
		<!--工具条-->
		<el-col class="toolbar">
			<el-col :span="17" style="text-align: center;">
				<h2>资产负债表</h2>
			</el-col>
		</el-col>
		<el-col class="toolbar">
			<el-col :span="24">
				<span>期间：</span>
				<el-select v-model="Period" @change='supRes' placeholder="请选择">
					<el-option v-for="item in Period_Date" :key="item.ID" :label="item.Name" :value="item.Code">
					</el-option>
				</el-select>
				<a class="wml"  @click="export2Excel">导出</a>
			</el-col>
		</el-col>
		<!--列表-->
		<el-table :data="tableData" max-height="700" border  highlight-current-row  v-loading="loading" element-loading-text="正在加载中" style="width: 72.2%">
			<el-table-column prop="ATitle" label="资产" header-align="center" width="280">
			</el-table-column>
			<el-table-column prop="AValue2" label="期末余额" :formatter="dealF" align="right" header-align="center" width="150">
			</el-table-column>
			<el-table-column prop="AValue1" label="年初余额" :formatter="dealF" align="right" header-align="center" width="150">
			</el-table-column>
			<el-table-column prop="BTitle" label="负债和所有权益(或股东权益)" header-align="center" width="280">
			</el-table-column>
			<el-table-column prop="BValue2" label="期末余额" :formatter="dealF" align="right" header-align="center" width="150">
			</el-table-column>
			<el-table-column prop="BValue1" label="年初余额" :formatter="dealF" align="right" header-align="center" width="150">
			</el-table-column>
		</el-table>
		</div>
	</section>
</template>

<script>
	import axios from '../../../util/axios';
	export default {
		name: 'Lose',
		data() {
			return {
				loading: true, //显示loading
				tableData: [], //数据列表
				Period: '', //默认第一个
				Period_Date: [], //日期集合
				nweDa: '',
				isdown:'',
			}
		},
		methods: {
			Fu_GetPeriodList() {
				axios
					.post('Fu_GetPeriodList')
					.then(res => {
						console.log(res);
						this.Period_Date = res;
						for(let i = 0; i < res.length; i++) {
							if(res[i].IsCurrent == 1) {
								this.Period = res[i].Code
							}
						}

					})
					.catch(err => {
						console.log(err);
					})

			},
			supRes() {
				console.log(this.Period)
				this.getList()
			},
			getList() { //异步获取客户列表                
				axios
					.post("GetBalanceBalance", {
						sPeriod: this.Period,
						sLevel: 0,
					})
					.then(data => {
						console.log(data)
						console.log(this.Period + '123');
						this.tableData = data;
						// this.daochu()
						setTimeout(() => {
							this.loading = false;
						}, 500);
					})
					.catch(err => {
						console.log(err);
					})
			},
			daochu(){
				axios
					.post('BExportData',
					{
		                sPeriod: this.Period,
						sLevel: 0,
		            })
					.then(res=>{
			                console.log(res)
			                //		                this.isdown = "http://192.168.1.169:8098"+res;
		                this.isdown = "http://www.zixun020.com/sccw"+res;
			                console.log(this.isdown)		                
			            })
					.catch(err => {
			                console.log(err);
			            })
			},
			// tishi(){
			// 	this.$message({
			// 		message: "下载中",
			// 		type: 'success'
			// 	});
			// },
			export2Excel() {
			　　require.ensure([], () => {
			　　　　const { export_json_to_excel } = require('../../../vendor/Export2Excel');
			　　　　const tHeader = ['资产', '期末余额', '年初余额', '负债和所有权益(或股东权益)','期末余额','年初余额'];
			　　　　const filterVal = ['ATitle', 'AValue2', 'AValue1', 'BTitle', 'BValue2','BValue1'];
			　　　　const list = this.tableData;
			　　　　const data = this.formatJson(filterVal, list);
			　　　　export_json_to_excel(tHeader, data, '资产负债表excel');
			　　})
			},
			formatJson(filterVal, jsonData) {
			　　return jsonData.map(v => filterVal.map(j => v[j]))
			},
			dealF(e,cell,cellValue) {
				console.log("1111111",cellValue)
				if(cellValue == 0){
					return ''
				}else{
					return cellValue
				}	   
			},
		},
		created() {
			this.Fu_GetPeriodList();
			// this.getList();
		},
		watch: {
			//			'Period': 'menban'
		},
		mounted() {
			// this.getList();
		}
	}
</script>

<style scoped lang="scss">
	@import '../../../common/css/index.css';
	.toolbar {
		h2 {
			font-weight: 100;
			margin: 0 auto;
		}
	}
	.wml{
		color: #fff;
	    background-color: #20a0ff;
	    border-color: #20a0ff;
	    font-size: 14px;
	    box-sizing: border-box;
	    padding: 10px 15px;
	    border-radius: 4px;
	    margin-left: 11px;
	}
</style>